package cp5_jdbc;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Properties;

public class FirstJDBC {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //            jdbc:mysql://服务器ip:端口/数据库名称
        String url = "jdbc:mysql://localhost:3306/tuhest";
        String username = "root";
        String password = "123456";


        // 1. 加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");//mysql的jdbc驱动名称
        // 2.获取连接
        Connection conn = DriverManager.getConnection(url, username, password);
        DatabaseMetaData metaData = conn.getMetaData();
        String databaseProductVersion = metaData.getDatabaseProductVersion();
        System.out.println("数据库的版本信息:" + databaseProductVersion);
        // 通过连接获取客户端信息
        Properties clientInfo = conn.getClientInfo();
        Enumeration<Object> keys = clientInfo.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement().toString();
            String value = clientInfo.getProperty(key);
            System.out.println("key:" + key + "==>value:" + value);
        }
        // 3.关闭连接
        conn.close();
    }
}
